function [paramsOpt,setup] = runOptimization(setup,params0)

params0Values           = struc2values(params0,setup.selectParams);
setup.lowerBoundsValues = struc2values(setup.lowerBounds,setup.selectParams);
setup.upperBoundsValues = struc2values(setup.upperBounds,setup.selectParams);
if setup.optim == 1
    InsigmaValues      = struc2values(setup.Insigma,setup.selectParams);  %The std deviation in the initial search distributions
    sigma              = 0.1;                          %The step size
    opts.SigmaMax      = 1;                            %The maximal value for sigma
    opts.LBounds       = setup.lowerBoundsValues;      %Lower bound for params
    opts.UBounds       = setup.upperBoundsValues;      %Upper bound for params
    opts.MaxIter       = setup.MaxIter;                %The maximum number of iterations
    opts.MaxFunEvals   = setup.MaxEvals;               %The maximum number of function evaluations
    opts.PopSize       = setup.PopSize;                %The population size
    opts.VerboseModulo = 1;                            %Display results after every 10'th iteration
    opts.TolFun        = setup.TolFun;                 %Function tolerance
    opts.TolX          = setup.TolX;                   %Tolerance in the parameters
    opts.Plotting      = 'off';                        %Dislpay plotting or not
    opts.Saving        = 'off';                        %Saving results
    paramsOptValuesCMEAS = cmaes_dsgeDisplay(@objectFunc,params0Values,sigma,InsigmaValues,opts,setup);    
    paramsOptValues = paramsOptValuesCMEAS;
elseif setup.optim == 2
    options = optimset('Display','iter','MaxIter',setup.MaxIter,'MaxFunEvals',setup.MaxEvals,'TolFun',setup.TolFun,'TolX',setup.TolX);   
    paramsOptValuesGRAD = lsqnonlin(@objectFunc,params0Values,[],[],options,setup);
    paramsOptValues = paramsOptValuesGRAD;
elseif setup.optim == 3
    options = optimset('Display','iter','MaxIter',setup.MaxIter,'MaxFunEvals',setup.MaxEvals,'TolFun',setup.TolFun,'TolX',setup.TolX);
    paramsOptValuesNM = fminsearch(@objectFunc,params0Values,options,setup);
    paramsOptValues = paramsOptValuesNM;
else
    paramsOptValues = params0Values;
end
paramsOpt = values2struct(paramsOptValues,setup.selectParams);
end